package Ep04_String.Offer_58;

/**
 * @author Jimmy Zhan WORKSTATION
 * @date 2023/3/21 21:15
 * 说明：剑指offer-58 解法二：StringBuilder：双指针分别翻转 --> 整体翻转，但是数组
 */

public class Mine_3 {
    public String reverseLeftWords(String s, int n) {
        char[] chars = s.toCharArray();
        reverseString(chars, 0, n-1);
        reverseString(chars, n, chars.length-1);
        reverseString(chars, 0, chars.length-1);
        return new String(chars);
    }

    public void reverseString(char[] chars, int left, int right){
        while (left < right){
            char temp = chars[left];
            chars[left] = chars[right];
            chars[right] = temp;
            left++;
            right--;
        }
    }
}
